package com.mt.api.util;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Objects;

/**
 * @Author: plover
 * @Date: 2020/08/06/8:17 下午
 * @Description:
 */
public class ParamsValid {


    private boolean isValid = true;

    private StringBuffer msgs = new StringBuffer();

    public ParamsValid validNotNull(String msg, Object paramValue) {
        if (Objects.isNull(paramValue)) {
            msgs.append(msg).append(";").append("\n");
            isValid = false;
        } else if (StringUtils.isEmpty(paramValue.toString())) {
            msgs.append(msg).append(";").append("\n");
            isValid = false;
        }
        return this;
    }

    public ParamsValid valid(String msg, boolean isValid) {
        if (!isValid) {
            msgs.append(msg).append(";").append("\n");
            isValid = false;
        }
        return this;
    }

    public ParamsValid validList(String msg, List paramValue) {
        if (CollectionUtils.isEmpty(paramValue)) {
            msgs.append(msg).append(";").append("\n");
            isValid = false;
        }
        return this;
    }

    public boolean isValid() {
        return this.isValid;
    }

    public String getMsg() {
        return this.msgs.toString();
    }
}
